clear all;
clc;

load mnist_train;

C = 1;

Y = yL';
Xt = xL';
clear xL;
clear yL;

l = size(Y,1);
[n,d] = size(Xt);

cls = unique(Y);
c = size(cls,1);
nump = c*(c-1)/2;

sz = zeros(c,1);
idx = cell(c,1);
for i = 1:c
    idx{i}=find(Y==cls(i));
    sz(i)=size(idx{i},1);
end

ix = cell(c,c);
Y = cell(c,c);

w = zeros(nump,d);
b = zeros(nump,1);

k = 1;
for i = 1:c
    for j = i+1:c
        disp(['Training pair ',int2str(i-1),' vs ',int2str(j-1)]);
        ix = [idx{i};idx{j}];
        X = Xt(ix,:);
        Y = [ones(sz(i),1);-ones(sz(j),1)];
        [w(k,:),b(k)] = primalSVMsedumi(X,Y);
        k = k+1;
    end
end
